package cn.umakr.service;

import cn.umakr.dao.Impl.UserDaoImpl;
import cn.umakr.dao.UserDao;
import cn.umakr.entity.User;

import java.util.List;

/**
 * Created by wangbo on 2017/7/19.
 */
public class UserService {

    private UserDao userDao = new UserDaoImpl();

    /**
     * 验证用户登录信息
     *
     * @param username 用户登录名
     * @param psssword 用户登录密码
     * @return 验证成功则返回user 否则返回null
     */
    public User validate(String username, String psssword) {
        List<User> users = userDao.findByProperty("uname", username);
        if (users.size() > 0) {
            User user = users.get(0);
            if (user.getUpasswd().equals(psssword)) {
                return user;
            }
        }
        return null;
    }

    /**
     * 查询所有用户列表数据
     *
     * @return 用户数据List集合
     */
    public List<User> listUser() {
        return userDao.findAll();
    }
}
